﻿using Inovout.Kuajing.Exports.Models;
using Inovout.Kuajing.Models;
using Inovout.Kuajing.Store.Console.WebSite;
using Inovout.Kuajing.Store.Models;
using Inovout.Locations;
using Inovout.Security;
using Inovout.Services;
using Inovout.Web;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Routing;

namespace Inovout.Kuajing.Store.Console.Web
{
    public class MvcApplication : WebApplication
    {
        public override void Run()
        {
            base.Run();
            CreateDataBase();
            InitData();
            //InitTestData();
            //InitImportData();

        }
        private void CreateDataBase()
        {
            Role role = new Role();
            User user = new User();
            TraditionalOrder tr = new TraditionalOrder();
            Location location = new Location();
            ShipmentOrder ship = new ShipmentOrder();
            FreeShippingExpression freeShippingExpression = new FreeShippingExpression();
            new Inovout.Repositories.DatabaseInstaller().InstallSchema();


        }


        private void InitData()
        {
            //OriginGoods originGoods = new OriginGoods();
            //float price = 12;
            //originGoods.MaxRetailPrice = price;
            //originGoods.MinRetailPrice = price;
            //originGoods.DistributionPrice = price;
            //originGoods.Stock = 12;
            //IRepositoryService<OriginGoods> originGoodsService = ComponentRegistry.Resolve<IRepositoryService<OriginGoods>>();
            //originGoodsService.Save(originGoods);

            //PurchaseOrder purchaseOrder = new PurchaseOrder();
            //purchaseOrder.Amount = price;
            //purchaseOrder.ConsigneeAddress = "加州大街";
            //purchaseOrder.ConsigneeName = "王三";
            //purchaseOrder.ConsigneePhone = "13902103212";
            //purchaseOrder.No = "123";

            //PurchaseOrderItem purchaseOrderItem = new PurchaseOrderItem();
            //purchaseOrderItem.Goods = originGoods;
            //purchaseOrderItem.GoodsName = "清水沐浴露";
            //purchaseOrderItem.GoodsPrice = price;
            //purchaseOrderItem.GoodsQuantity = 13;
            //purchaseOrderItem.PurchaseOrder = purchaseOrder;

            //PurchaseOrderItem purchaseOrderItem1 = new PurchaseOrderItem();
            //purchaseOrderItem1.Goods = originGoods;
            //purchaseOrderItem1.GoodsName = "花王沐浴露";
            //purchaseOrderItem1.GoodsPrice = price;
            //purchaseOrderItem1.GoodsQuantity = 14;
            //purchaseOrderItem1.PurchaseOrder = purchaseOrder;

            //IRepositoryService<PurchaseOrderItem> purchaseOrderItemService = ComponentRegistry.Resolve<IRepositoryService<PurchaseOrderItem>>();
            //purchaseOrderItemService.Save(purchaseOrderItem);
            //purchaseOrderItemService.Save(purchaseOrderItem1);


            Location location = new Location();
            location.ZoneCode = 1;
            location.ScopeCode = 2;
            location.Name = "中国";
            location.Parent = null;
            location.EnglishName = "china";

         

            //创建区域
            Location hb = new Location();
            hb.ZoneCode = 11;
            hb.ScopeCode = 21;
            hb.Name = "华南";
            hb.Parent = location;
            hb.EnglishName = "huan";


            //创建省
            Location js = new Location();
            js.ZoneCode = 111;
            js.ScopeCode = 211;
            js.Name = "江苏";
            js.Parent = hb;
            js.EnglishName = "js";



            //创建城市
            Location nj = new Location();
            nj.ZoneCode = 1111;
            nj.ScopeCode = 2111;
            nj.Name = "南京";
            nj.Parent = js;
            nj.EnglishName = "nanj";

            Location sz = new Location();
            sz.ZoneCode = 1112;
            sz.ScopeCode = 2112;
            sz.Name = "苏州";
            sz.Parent = js;
            sz.EnglishName = "suz";

            ILocationService locationService = ComponentRegistry.Resolve<LocationService>();
            locationService.Save(nj);
            locationService.Save(sz);


        }
    }


}
